// Copyright (C) joyinter
// All rights reserved.
// 
// Author : dengxinguo
// Date   : 2004-12-14

#include "stdafx.h"


#include "mainuiman.h"
#include <common/ui/utility.h>
#include "loginwnd.h"
#include "loginclue.h"


IMPLEMENT_DYNAMIC(CJoyLoginClueWnd, CJoyWnd)

//##ModelId=44C4B5E2014A
CJoyLoginClueWnd::CJoyLoginClueWnd(void)
{
    m_name = "loginclue_window";
    m_skinArea  = true;   
}

//##ModelId=44C4B5E2014C
CJoyLoginClueWnd::~CJoyLoginClueWnd(void)
{
}


BEGIN_MESSAGE_MAP(CJoyLoginClueWnd, CJoyWnd)
    ON_WM_CREATE()
    ON_WM_NCHITTEST()
    ON_WM_DESTROY()
    ON_WM_TIMER()
END_MESSAGE_MAP()

//##ModelId=44C4B5E20157
void CJoyLoginClueWnd::OnCancel()
{
   
}

//##ModelId=44C4B5E2012E
void CJoyLoginClueWnd::CM_Draw(Graphics& graph)
{
    int w = m_area.Width();
    int h = m_area.Height();
    // draw edge
    {
        Pen pen1(Color(0xFFCCCCCC), 2.0f);
        graph.DrawRectangle(&pen1, 0, 0, w, h);
        Pen pen2(Color(0xFF666666));
        graph.DrawRectangle(&pen2, 2, 2, w-6, h-6);
    }

    // draw back
    {
        Color c[5] = 
        {
            Color(0xFFFFFFFF),
            Color(0xFFFFFFFF),
            Color(0xFFE6E6E6),
            Color(0xFFFFFFFF),
            Color(0xFFFFFFFF),
        };
        REAL p[5] = 
        {
            0.0f, 0.022f, 0.022f, 0.4f, 1.0f,
        };
        JoyLinearFillRectV(graph,
            Rect(3, 3, w-7, h-7),
            c, p, 5);
    }

}

//##ModelId=44C4B5E2013E
void CJoyLoginClueWnd::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);

    CWnd* pParent = GetParent();
    if(pParent != NULL)
    {
        pParent->MoveWindow(m_area);
        pParent->CenterWindow();
    }
}
//##ModelId=44C4B5E2013B
void CJoyLoginClueWnd::CM_CancelClick(CJoyButton*)
{
 
    CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }
    CJoyLoginWnd* loginWnd = ((CJoyMainManager*)JoyGetManager())->GetLoginWnd();
	if(loginWnd->m_hWnd != NULL)
	{
		
	   loginWnd->PostMessage(WM_CLOSE);
	}
   
}

//##ModelId=44C4B5E20138
void CJoyLoginClueWnd::CM_RetryClick(CJoyButton*)
{
   
	
    CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }
	m_loginwnd->m_bRetry=true;

}
//##ModelId=44C4B5E20158
int CJoyLoginClueWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CJoyWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

	CJoyImageCtrl *ImagCtrl=new CJoyImageCtrl();
	ImagCtrl->m_name="logo_image";
	ImagCtrl->Create(this, CRect(0, 0, 10, 10));


	m_btnRetry     = new CJoyButton();
    m_btnRetry->m_name  = "btn_retry";
    m_btnRetry->Create(this, CRect(0, 0, 10, 10));
    m_btnRetry->SetClickEvent(this, (CJoyButton::PClickEvent)&CJoyLoginClueWnd::CM_RetryClick);
    m_btnRetry->m_hitTest = HTCLIENT;

    m_btnCancel     = new CJoyButton();
    m_btnCancel->m_name  = "btn_cancel";
    m_btnCancel->Create(this, CRect(0, 0, 10, 10));
    m_btnCancel->SetClickEvent(this, (CJoyButton::PClickEvent)&CJoyLoginClueWnd::CM_CancelClick);
    m_btnCancel->m_hitTest = HTCLIENT;

  

	CJoyLabel *statusText = new CJoyLabel();
    statusText->m_name = "logining_clue";
    statusText->Create(this, CRect(0, 0, 100, 20));
	statusText->SetTextAlign(StringAlignmentNear);
	statusText->SetTextFormat(StringFormatFlagsDisplayFormatControl);

	CJoyLabel *LabelLogo = new CJoyLabel();
    LabelLogo->m_name = "logo_text";
    LabelLogo->Create(this, CRect(0, 0, 100, 20));
	LabelLogo->SetTextAlign(StringAlignmentNear);
	LabelLogo->SetTextFormat(StringFormatFlagsDisplayFormatControl);

	m_labelErrClue = new CJoyLabel();
    m_labelErrClue->m_name = "label_clue";
    m_labelErrClue->Create(this, CRect(0, 0, 100, 20));
	m_labelErrClue->SetTextAlign(StringAlignmentNear);
	m_labelErrClue->SetTextFormat(StringFormatFlagsDisplayFormatControl);
	

    JoyGetManager()->RegWnd(this);
	m_iClueLength=m_labelErrClue->GetText().GetLength();
    m_labelErrClue->SetVisible(false);
    m_btnRetry->SetVisible(false);
  
    return 0;
}

//##ModelId=44C4B5E2015B
LRESULT CJoyLoginClueWnd::OnNcHitTest(CPoint point)
{
    CPoint p(point);
    ScreenToClient(&p);
    UINT r = (UINT)DoHitTest(p);
    if(r != 0)
    {
        return r;
    }
    return (UINT)HTTRANSPARENT;
}

//##ModelId=44C4B5E20167
void CJoyLoginClueWnd::OnDestroy()
{
    JoyGetManager()->UnregWnd(this);

    CJoyWnd::OnDestroy();
}



// CJoyLoginClueDlg dialog

CJoyLoginClueDlg* m_LoginClueDlg = NULL;

IMPLEMENT_DYNAMIC(CJoyLoginClueDlg, CDialog)

//##ModelId=44C4B5E20186
CJoyLoginClueDlg::CJoyLoginClueDlg(CWnd* pParent)
	: CDialog(CJoyLoginClueDlg::IDD, pParent)
{
	
    m_LoginClueDlg   = this;
	m_loginwnd=(CJoyLoginWnd *)pParent;
	m_loginwnd->m_LoginClueDlg=this;
	
}

//##ModelId=44C4B5E20188
CJoyLoginClueDlg::~CJoyLoginClueDlg()
{
    m_LoginClueDlg   = NULL;
	
}

//##ModelId=44C4B5E2018F
void CJoyLoginClueDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CJoyLoginClueDlg, CDialog)
    ON_WM_CREATE()
    ON_WM_SIZE()
    ON_WM_NCHITTEST()
   // ON_WM_CLOSE()
END_MESSAGE_MAP()


// CJoyLoginClueDlg message handlers

//##ModelId=44C4B5E20197
int CJoyLoginClueDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_LoginClueWnd.Create(this, CRect(0, 0, 10, 10));
	m_loginwnd->m_LoginClueWnd=&m_LoginClueWnd;
	m_LoginClueWnd.m_loginwnd=m_loginwnd;
	m_loginwnd->m_bHaveLoginClueWnd=true;
    return 0;
}

//##ModelId=44C4B5E2019A
void CJoyLoginClueDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialog::OnSize(nType, cx, cy);

    SetWindowRgn(CreateRoundRectRgn(0, 0, cx, cy, 2, 2), FALSE);
    
}

//##ModelId=44C4B5E201A6
LRESULT CJoyLoginClueDlg::OnNcHitTest(CPoint point)
{
    CDialog::OnNcHitTest(point);
    return HTCAPTION;
}

